package com.zmn.oms.task.listener;

import com.alibaba.fastjson.JSONObject;
import com.zmn.manager.mq.annotation.AliyunMQHandler;
import com.zmn.manager.mq.annotation.AliyunMQListener;
import com.zmn.oms.manager.utils.OmsMqTagConsts;
import com.zmn.oms.model.entity.visit.OrderVisit;
import com.zmn.oms.zmn.business.interfaces.work.OrderWorkMultipleVisitBService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 类描述：工单上门监听
 *
 * @author lujia
 * @date 2018/11/30 16:53
 */
@Slf4j
@AliyunMQListener(topic = "${spring.mq.topic.oms}")
@Component
public class OrderWorkVisitListener {

    @Autowired
    private OrderWorkMultipleVisitBService orderWorkMultipleVisitBService;

    /**
     * 工单同步es消息监听
     * @param message
     */
    @AliyunMQHandler(tags = OmsMqTagConsts.MULTIPLE_VISIT_WARNING_TAG)
    public void orderWorkChange(String message){
        try {
            log.info("#mq#orderwork#visit#message: " + message);
            OrderVisit orderVisit = JSONObject.parseObject(message, OrderVisit.class);
            orderWorkMultipleVisitBService.processMultipleVisitWarning(orderVisit);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("#mq#orderwork#visit#error: " + e.getMessage());
        }
    }
}
